#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
const int MAXN=1000001,MAXM=5001; 
int c[MAXN],s[MAXN];
int find_min_hash_mod(vector<int> &a,int n,int k){
	sort(a.begin(),a.end());
	memset(c,0,sizeof(c));
	for(int i=1;i<n;i++)for(int j=0;j<i;j++)c[a[i]-a[j]]++;
	for(int m=1;m<=a[n-1];m++){
		int sum=0;//sum(|a[i]-a[j]|%m==0) foreach pair(i,j) in a 
		for(int j=m;j<=a[n-1]&&sum<=k*(k+1)/2;j+=m)sum+=c[j];
		if(sum>k*(k+1)/2)continue;
		int cnt=0,i=0;//the delete num
		for(i=0;i<n&&cnt<=k;i++)if(++s[a[i]%m]>1)cnt++;
		if(cnt<=k)return m;
		for(int j=0;j<i;j++)s[a[j]%m]=0;
		}
	return -1;
	}
vector<int>v;
int main(){
	int n,k,x;
	while(cin>>n>>k){
		v.clear();
		for(int i=0;i<n;i++){
			cin>>x;
			v.push_back(x);
			}
		cout<<find_min_hash_mod(v,n,k)<<endl;
		}
    return 0;
    }
